﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
using Teenusekiht;
using System.ServiceModel;

public partial class Kohvik_Register : System.Web.UI.Page
{
    IService1 sc;

    protected void createUserBtn_Click(object sender, EventArgs e)
    {
        sc = new ChannelFactory<IService1>("Serv").CreateChannel();
        string userName = UserName.Text;
        string pass = Password.Text;

        int userRoleID = 1;
        string result = sc.RegistreeriKasutaja(userName, pass, userRoleID, Rakendus.RAKENDUSE_KOOD); //"Kasutaja loomine õnnestus."
        sc.Dispose();

        if (result == "Kasutaja loomine õnnestus.")
        {
            //var saatja = new MailAddress("example@example.com", "Example");
            //var saaja = new MailAddress(Email.Text, userName);  //"itelga@itcollege.ee", "Ilmar");
            //MailMessage kiri = new MailMessage(saatja, saaja);
            //kiri.Body = "Said selle kirja kuna registreerisid end MinuKohvik lehele. Palun kinnita oma konto vajutades siia.";
            //kiri.Subject = "MinuKohvik kasutaja kinnitamine.";
            //string meiliServeriNimi = "localhost";
            //SmtpClient meiliKlient = new SmtpClient(meiliServeriNimi);
            //meiliKlient.Send(kiri);

            Response.Redirect("~/Default.aspx");
        }
        else 
        {
            ErrorMessage.Visible = true;
            ErrorMessage.Text = result; 
        }
    }

    protected void UserName_Load(object sender, EventArgs e)
    {
        (sender as TextBox).Focus();
    }
}
